namespace ui {
	/**
	 * @param title 标题;
	 * @param msg string/number[];
	 * @param type 类型: 1.文本, 2.RewardPreview;
	 * @param hideDrop 是否显示RewardPreview的'掉落角标';
	 */
	export function msgshow(title: string, msg: any, type: number, hideDrop = false): void {
		const box = new DlgMsgShow(title, msg, type, hideDrop);
		box.toggle();
	}

	class DlgMsgShow extends PopupPanel {
		private static instance: DlgMsgShow;

		public static ins(title: string, msg: any, type: number, hideDrop: boolean): DlgMsgShow {
			if (!this.instance) {
				this.instance = new DlgMsgShow(title, msg, type, hideDrop);
			}
			return this.instance;
		}

		override btnClose: eui.Button;

		override title: string;

		msg: any;

		type: number;

		hideDrop = false;

		ti: eui.Label;

		lbMsg: eui.Label;

		rwPreview: RewardPreview;

		constructor(title: string, msg: any, type: number, hideDrop: boolean) {
			super();
			this.skinName = 'ui_msgshow';
			this.title = title;
			this.msg = msg;
			this.type = type;
			this.hideDrop = hideDrop;
			allCenter(this);
		}

		override childrenCreated(): void {
			this.outsideClose = true;

			this.btnClose.addEventListener('touchTap', this.onClose, this);

			this.ti.text = this.title;

			this.showType();
			this.setMsg();
		}

		setMsg(): void {
			switch (this.type) {
				case 1: {
					this.lbMsg.text = this.msg;
					break;
				}
				case 2: {
					if (this.hideDrop) {
						this.rwPreview.hideDrop();
					}
					this.rwPreview.setRewardInfo(this.msg);
					break;
				}
				default:
					break;
			}
		}

		showType(): void {
			this.lbMsg.visible = this.type === 1;
			this.rwPreview.visible = !this.lbMsg.visible;
		}
	}
}
